/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "hks_crypto_hal_common.h"

uint8_t HksCryptoHalCommon::HexChar(char hex) const
{
    if (hex >= '0' && hex <= '9') {
        return hex - '0';
    } else if (hex >= 'A' && hex <= 'F') {
        return hex - 'A' + 0X0A;
    } else if (hex >= 'a' && hex <= 'f') {
        return hex - 'a' + 0X0A;
    } else {
        return 0;
    }
}

uint8_t HksCryptoHalCommon::ReadHex(const uint8_t hex[2]) const
{
    return HexChar(*hex) * 16 + HexChar(*(hex + 1));
}